package com.web.kdl.common.result;

/**
 * @Author： shulibin
 * @Date： 2025/7/21 11:32
 * @Describe： 枚举类返回码
 */
public enum ReturnCode {
    SUCCESS(200, "成功"),
    FAIL(500, "失败"),
    NOT_FOUND(404, "未找到"),
    UNAUTHORIZED(401, "登录已过期，请重新登录"),
    FORBIDDEN(403, "禁止访问"),
    NOT_ACCEPTABLE(406, "请求的格式不可接受"),
    REQUEST_TIMEOUT(408, "请求超时"),
    CONFLICT(409, "冲突"),
    INTERNAL_SERVER_ERROR(500, "服务器内部错误"),
    SERVICE_UNAVAILABLE(503, "服务不可用");

    private final int code;
    private final String message;
    ReturnCode(int code, String message) {
        this.code = code;
        this.message =message;
    }
    public int getCode() {
        return code;
    }
    public String getMessage() {
        return message;
    }
    public static ReturnCode valueOfCode(int code) {
        for (ReturnCode returnCode : values()) {
            if (returnCode.getCode() == code) {
                return returnCode;
            }
        }
        throw new IllegalArgumentException("No matching constant for [" + code + "]");
    }
}
